//
//  YKClientDataVisitInfoView.m
//  YunKang
//
//  Created by leoking870 on 2017/11/30.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKClientDataVisitInfoView.h"
#import "YKInputView.h"
#import "YKClientDataDetail.h"
#import "YKInputMultilineView.h"

@interface YKClientDataVisitInfoView ()
@property(nonatomic, strong) YKClientDataDetail *dataDetail;
@end


@implementation YKClientDataVisitInfoView

- (instancetype)initWithClientModel:(YKClientDataDetail *)dataDetail {
    self = [super initWithFrame:CGRectZero];
    if (self) {
        _dataDetail = dataDetail;
        YKInputView *registerMoneyView = [[YKInputView alloc] initWithTitle:@"注册资金" input:self.dataDetail.REG_CAPITAL];
        registerMoneyView.tf_id = @"reg_capital";
        [self addSubview:registerMoneyView];

        YKInputView *foundDateView = [[YKInputView alloc] initWithTitle:@"成立时间" input:self.dataDetail.ESTABLISH];
        foundDateView.tf_id = @"establish";
        foundDateView.type = YKInputViewTypeDate;
        foundDateView.dateFormat = @"yyyy-MM-dd";
        [self addSubview:foundDateView];

        YKInputView *doctorCountView = [[YKInputView alloc] initWithTitle:@"医生数量" input:self.dataDetail.DOCTORCOUNT];
        doctorCountView.tf_id = @"doctorcount";
        [self addSubview:doctorCountView];

        YKInputView *nerseCountView = [[YKInputView alloc] initWithTitle:@"护工数量" input:self.dataDetail.NURSECOUNT];
        nerseCountView.tf_id = @"nursecount";
        [self addSubview:nerseCountView];

        YKInputMultilineView *currentChannelView = [[YKInputMultilineView alloc] initWithTitle:@"现有渠道" input:self.dataDetail.PURCHASING_CHANNEL];
        currentChannelView.tf_id = @"purchasing_channel";
        [self addSubview:currentChannelView];


        YKInputMultilineView *saleDrugsView = [[YKInputMultilineView alloc] initWithTitle:@"在售主流药品" input:self.dataDetail.MAINSTREAM_DRUGS];
        saleDrugsView.tf_id = @"mainstream_drugs";
        [self addSubview:saleDrugsView];

        YKInputMultilineView *yearBuyView = [[YKInputMultilineView alloc] initWithTitle:@"年采购情况" input:self.dataDetail.PURCHASING_SITUATION];
        yearBuyView.tf_id = @"purchasing_situation";
        [self addSubview:yearBuyView];

        YKInputMultilineView *yearSaleView = [[YKInputMultilineView alloc] initWithTitle:@"年销售情况" input:self.dataDetail.SALES_SITUATION];
        yearSaleView.tf_id = @"sales_situation";
        [self addSubview:yearSaleView];

        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:[YKInputView class]]) {
                ((YKInputView *) view).disableInputBackgroundColor = [UIColor tf_colorWithHexString:@"#f2f2f2"];
                ((YKInputView *) view).contentTopInset = 0;
                ((YKInputView *) view).editable = NO;
            }
            if ([view isKindOfClass:[YKInputMultilineView class]]) {
                ((YKInputMultilineView *) view).editable = NO;
            }
        }
        [self.subviews mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.equalTo(self);
            make.width.mas_equalTo(self.mas_width);
        }];
        [self.subviews mas_alignAlongAxis:MASAxisTypeVertical fixedSpace:@4 leadSpace:8 tailSpace:8];
    }
    return self;
}

- (NSDictionary *)values {
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[YKInputView class]]) {
            dictionary[view.tf_id] = ((YKInputView *)view).input;
        }
        if ([view isKindOfClass:[YKInputMultilineView class]]) {
            dictionary[view.tf_id] = ((YKInputMultilineView *)view).input;
        }
    }
    return [dictionary copy];
}

- (void)setEditable:(BOOL)editable {
    _editable = editable;
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[YKInputView class]]) {
            ((YKInputView *) view).editable = editable;
        }
        if ([view isKindOfClass:[YKInputMultilineView class]]) {
            ((YKInputMultilineView *) view).editable = editable;
        }
    }
}

@end
